package com.syq.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.syq.annotation.RequiresPermissionsDesc;
import com.syq.pojo.DtsUser;
import com.syq.pojo.DtsUserAccount;
import com.syq.service.DtsUserAccountService;
import com.syq.service.DtsUserService;
import com.syq.util.ResponseUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName: UserController
 * @Description: TODO
 * @Create by: syq
 * @Date: 2022/7/25 20:47
 */

@RestController
@RequestMapping("/admin/user")
@CrossOrigin
public class UserController {

    @Autowired
    private DtsUserService dtsUserService;

    @Autowired
    private DtsUserAccountService dtsUserAccountService;

    @RequiresPermissionsDesc(menu = {"用户管理","会员管理"},button = "查询")
    @RequiresPermissions(value = "admin:user:list")
    @GetMapping("/list")
    public Object userList(@RequestParam(defaultValue = "1")Integer page,
                           @RequestParam(defaultValue = "10")Integer limit, String phone,
                           @RequestParam(defaultValue = "add_time")String sort,
                           @RequestParam(defaultValue = "desc")String order,String username){
        IPage<DtsUser> userIPage=dtsUserService.findByPage(page,limit,username,phone,sort,order);
        Map<String,Object> map=new HashMap<>();
        map.put("total",userIPage.getTotal());
        map.put("items",userIPage.getRecords());
        return ResponseUtil.ok(map);
    }

    @RequiresPermissionsDesc(menu = {"用户管理","会员管理"},button = "设置代理")
    @RequiresPermissions(value = "admin:user:detailApprove")
    @GetMapping("/detailApprove")
    public Object userDetailApprove(Integer id){
        DtsUserAccount userAccount=dtsUserAccountService.findById(id);
        return ResponseUtil.ok(userAccount);
    }
}




